//
//  HZGoodsModel.m
//  app
//
//  Created by 刘华舟 on 15/5/20.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZGoodsModel.h"
#import "NSDictionary+SafetyGet.h"

@implementation HZGoodsModel


+ (CGFloat)tableViewCellHeight
{
    return floor(UF(kHZGoodsTabViewCellHeight));
};

+ (NSInteger)tableViewCellUFHeight{
    return kHZGoodsTabViewCellHeight;
}

- (CGFloat)collectionViewCellHeight{
    switch (self.modelType) {
        case HZGoodsModelTypeNormal:
            return floor(UF(kHZGoodsColViewHeight));
            break;
        case HZGoodsModelTypeTeMai:
            return floor(UF(kHZGoodsColViewHeight+kHZGoodsViewTeMaiBtnHeight+kHZGoodsColViewMargin/2+kSizeMallViewMargin));
        default:
            return floor(UF(kHZGoodsColViewHeight));
            break;
    }
    
}
- (NSInteger)collectionCellUFHeight{
    switch (self.modelType) {
        case HZGoodsModelTypeNormal:
            return floor(kHZGoodsColViewHeight);
            break;
        case HZGoodsModelTypeTeMai:
            return floor(kHZGoodsColViewHeight+kHZGoodsViewTeMaiBtnHeight+kHZGoodsColViewMargin+kHZGoodsColViewMargin/2);
        default:
            return floor(kHZGoodsColViewHeight);
            break;
    }
}


+ (instancetype)modelWithDictionary:(NSDictionary *)dict{
    return [[HZGoodsModel alloc] initModelWithDictionary:dict];
}
- (instancetype)initModelWithDictionary:(NSDictionary *)dict{
    if (self = [super init]) {
        _shopID = [dict stringForKey:APIKEY_mall_shop_id nilValue:@"0"];
        _brandID =  [dict stringForKey:APIKEY_mall_brand_id nilValue:@"0"];
        _classifyID = [dict stringForKey:APIKEY_mall_classify_id nilValue:@"0"];
        _keywords = [dict stringForKey:APIKEY_mall_keywords nilValue:@""];
        _productID = [dict stringForKey:APIKEY_mall_product_id nilValue:@"0"];
        _productTitle = [dict stringForKey:APIKEY_mall_product_title nilValue:@""];
        _picURL = [dict stringForKey:APIKEY_mall_pic nilValue:@""];
        _picWidth = [dict stringForKey:APIKEY_mall_width nilValue:@"0"];
        _picHeight = [dict stringForKey:APIKEY_mall_height nilValue:@"0"];
        CGFloat sPrice = [dict floatForKey:APIKEY_mall_sale_price nilValue:0.00f];
        _salePrice = [NSString stringWithFormat:@"%.2f", sPrice];
        CGFloat tPrice = [dict floatForKey:APIKEY_mall_tag_price nilValue:0.00f];
        _tagPrice = [NSString stringWithFormat:@"%.2f", tPrice];
        _productNum = [dict stringForKey:APIKEY_mall_product_num nilValue:@"0"];
        _saleNum = [dict stringForKey:APIKEY_mall_sale_num nilValue:@"0"];
        _shopName = [dict stringForKey:APIKEY_mall_shop_name nilValue:@""];
        _brandName = [dict stringForKey:APIKEY_mall_brand_name nilValue:@""];
        _promotion = [dict arrayForKey:APIKEY_mall_promotion];
        _jifen = [dict stringForKey:APIKEY_mall_jifen nilValue:@"0"];
        _ptype = [dict stringForKey:APIKEY_mall_ptype nilValue:@"0"];
        
        //商品收藏属性
        //根据某个属性来判断是不是特卖商品
        //_modelType = HZGoodsModelTypeNormal; or

        //商品收藏属性
        _modelType = HZGoodsModelTypeNormal;

        _srvStartInterval = [dict stringForKey:APIKEY_mall_starttime nilValue:@"0"];
        _srvEndInterval = [dict stringForKey:APIKEY_mall_endtime nilValue:@"0"];
    }
    
    return self;
}


@end
